//
//  IncomeGoldDetailController.m
//  WuJieLive
//
//  Created by iMac on 2017/11/21.
//  Copyright © 2017年 zhk. All rights reserved.
//

#import "IncomeGoldDetailController.h"
#import "MyWalletCell.h"
#import "WalletDetailController.h"

@interface IncomeGoldDetailController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic , strong) UITableView * tableview;
@property (nonatomic , strong) NSMutableArray * dataArray;
@property (nonatomic , assign) NSInteger index;

@end

@implementation IncomeGoldDetailController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}
-(void)setUI
{
    self.dataArray = [NSMutableArray array];
    self.index = 1;
    self.tableview = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight - 40) style:(UITableViewStylePlain)];
    self.tableview.dataSource = self;
    self.tableview.delegate = self;
    [self.tableview registerNib:[UINib nibWithNibName:@"MyWalletCell" bundle:nil] forCellReuseIdentifier:@"MyWalletCell"];
    self.tableview.tableFooterView = [UIView new];
    self.tableview.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:self.tableview];
}
-(void)setData
{
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    NSDictionary * dict = @{@"token":self.userToken,@"page":[NSString stringWithFormat:@"%ld",self.index],@"type":@"in"};
    [HTTPTool POSTForm:[NSString stringWithFormat:@"%@deposit-account/gold-money-lists",BaseUrl] para:dict success:^(BOOL isSuccess, id responseObject) {
        [MBProgressHUD hideHUDForView:self.view animated:YES];
        if (isSuccess) {
            NSArray * array = [[responseObject objectForKey:@"data"] objectForKey:@"contents"];
            for (int i = 0; i < array.count; i ++) {
                WalletDetailModel * model = [[WalletDetailModel alloc]init];
                [model setValuesForKeysWithDictionary:array[i]];
                [self.dataArray addObject:model];
            }
            [self.tableview reloadData];
        }
    } failure:^(NSError *error) {
        [MBProgressHUD hideHUDForView:self.view animated:YES];
    }];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    MyWalletCell * cell = [tableView dequeueReusableCellWithIdentifier:@"MyWalletCell" forIndexPath:indexPath];
    [cell bindDataWithModel:self.dataArray[indexPath.row]];
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 65;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    WalletDetailController * vc = [[WalletDetailController alloc]init];
    [self.navigationController pushViewController:vc animated:YES];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.dataArray.count;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
